import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gczn_hd/app/core/base/base_view.dart';
import 'package:gczn_hd/app/core/base/handle_mixin.dart';
import 'package:gczn_hd/app/core/widget/custom_app_bar.dart';
import 'package:gczn_hd/app/core/widget/gczn_card.dart';
import 'package:gczn_hd/app/modules/eam/spotcheck_detail/widget/check_list.dart';
import 'package:gczn_hd/app/modules/eam/spotcheck_detail/widget/machine_msg.dart';
import 'package:gczn_hd/app/routes/app_pages.dart';

import 'package:get/get.dart';

import '../../../../core/values/app_colors.dart';
import '../../../../core/values/app_values.dart';
import '../../../../core/values/text_styles.dart';
import '../controllers/spotcheck_detail_controller.dart';

class SpotcheckDetailView extends BaseView<SpotcheckDetailController> with HandleMixin{

  SpotcheckDetailView(){
    controller.onViewInit();
  }

  final Size btnSize = Size(204.w, 60.h);

  @override
  PreferredSizeWidget? appBar(BuildContext context) => CustomAppBar(appBarTitleText: "点检计划详细", actions: [
    Obx((){
        return controller.pageType.value == 1 ? SizedBox(
          width: btnSize.width,
          height: btnSize.height,
          child: ElevatedButton(
              onPressed: (){
                showConfirm(content: "是否执行点检？", onConfirm: (){
                  Get.offAndToNamed(Routes.SPOTCHECK_DETAIL, arguments: {"pageType": 2});
                }, onCancel: (){
                  Get.back();
                }, confirmText: "执行", cancelText: "取消");
              },
              style: btnStyle,
              child: Text("执行点检", style: submitButtonText,)
          ),
        ) : controller.pageType.value == 2  ? _buildButtonGroup() : Container();
    })

    ,SizedBox(width: AppValues.size30.w,)
  ],
  );

  Widget _buildButtonGroup(){
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        SizedBox(width: btnSize.width, height: btnSize.height, child:  ElevatedButton(
          onPressed: () {
            showToast("保存中");
          },
          style: ElevatedButton.styleFrom(
            backgroundColor: AppColors.gcznPrimaryColorCan,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(AppValues.margin_12.r),
                bottomLeft: Radius.circular(AppValues.margin_12.r),
              ),
            ),
          ),
          child: Text('保存', style: submitButtonText,),
        ),),
        SizedBox(width: btnSize.width, height: btnSize.height, child:  ElevatedButton(
          onPressed: () {
            showToast("提交了");
          },
          style: ElevatedButton.styleFrom(
            backgroundColor: AppColors.gcznPrimaryBlueColorBtn,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.only(
                topRight: Radius.circular(AppValues.margin_12.r),
                bottomRight: Radius.circular(AppValues.margin_12.r),
              ),
            ),
            // fixedSize: Size(btnSize.width.w, btnSize.height.h)
          ),
          child: Text('提交', style: submitButtonText,),
        )),
        SizedBox(
          width: AppValues.size30.w,
        )
      ],
    );
  }

  @override
  Widget body(BuildContext context) {
    const double boxWidth = 587.0;
    const double boxHeight = 900.0;

    return SingleChildScrollView(
      child: Container(
        padding: EdgeInsets.only(top: AppValues.size40.h, left: AppValues.size40.w, right: AppValues.size40.w),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            GcznCard(
              child: Container(
                width: boxWidth.w,
                height: boxHeight.h,
                padding:  EdgeInsets.only(top: AppValues.size28.h, left: AppValues.size26.w, bottom: AppValues.size28.h, right: AppValues.size26.w),
                child: SingleChildScrollView(
                  child: MachineMsg(),
                ),
              ),
            ),
            SizedBox(width: AppValues.size40.w,),
            Expanded(
              flex: 1,
              child: GcznCard(
                child: Container(
                    height: boxHeight.h,
                    padding: EdgeInsets.only(top: AppValues.size28.h, left: AppValues.size26.w, bottom: AppValues.size28.h, right: AppValues.size26.w),
                    child: CheckList()
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
  
}
